package com.egao.ap.service.impl;

import com.egao.ap.biz.InformationBiz;
import com.egao.ap.entity.Information;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.ap.mapper.InformationZanMapper;
import com.egao.ap.entity.InformationZan;
import com.egao.ap.service.InformationZanService;
import org.springframework.stereotype.Service;
import com.egao.ap.biz.InformationZanBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 点赞服务实现类
 * @author : Doman
 * @date : 2020-10-23 23:27:18
 * @version ：1.0
 */
@Service
public class InformationZanServiceImpl /*extends ServiceImpl<InformationZanMapper, InformationZan> */implements InformationZanService {

	@Autowired
	private InformationZanBiz informationZanBiz;
	@Autowired
	private InformationBiz informationBiz;

    /**
    @Override
    public PageResult<InformationZan> listPage(PageParam<InformationZan> page) {
        List<InformationZan> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<InformationZan> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, InformationZan informationZan, User loginUser)  throws Exception{
        return informationZanBiz.list(page,informationZan,loginUser);
    }

    @Override
    public JsonResult list(InformationZan informationZan, User loginUser) {
        return JsonResult.ok().setData(informationZanBiz.list(informationZan,loginUser));
    }

    @Override
    public JsonResult getById(InformationZan informationZan) {
        return JsonResult.ok().setData(informationZanBiz.getById(informationZan));
    }

    @Transactional
    @Override
    public JsonResult save(InformationZan informationZan, User loginUser) {
        Information information = new Information();
        information.setId(informationZan.getInfoid()+"");
        informationBiz.updateUpTime(information, loginUser);
        return JsonResult.ok("添加成功").put("id",informationZanBiz.save(informationZan, loginUser));
    }

    @Transactional
    @Override
    public JsonResult update(InformationZan informationZan, User loginUser) {
        if (informationZanBiz.update(informationZan, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(InformationZan informationZan, User loginUser) {
        InformationZan informationZan2 = informationZanBiz.getById(informationZan);
        Information information = new Information();
        information.setId(informationZan2.getInfoid()+"");
        informationBiz.updateUpTime(information, loginUser);
        if (informationZanBiz.remove(informationZan, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
